import {
  createRouter,
  createWebHashHistory,
  createWebHistory
} from 'vue-router'
import HomeView from '../views/home'

const routes = [{
  path: '/',
  name: 'home',
  redirect: '/home', //重定向到首页

  // redirect: '/complain', //重定向到投诉页面
  component: HomeView,
  children: [

    {
      path: '/home',
      name: '骨干云池',
      component: () => import('../views/gugan'), //骨干云池
    },
    {
      path: '/idc',
      name: 'IDC资源',
      component: () => import('../views/IDC'), //5gtob网络
    },
    {
      path: '/fiveG',
      name: '5gtob网络',
      component: () => import('../views/fiveG'),
    },
    {
      path: '/complain',
      name: '投诉概况',
      component: () => import('../views/complain'),
      meta: {
        title: "湖北省投诉概况可视化图表"
      },
    }
  ]
}, ]

const router = createRouter({
  history: createWebHistory(), //vue3 路由配置修改为history
  routes
})

router.beforeEach((to, from, next) => { //beforeEach是router的钩子函数，在进入路由前执行
  if (to.meta.title) { //判断是否有标题
    document.title = to.meta.title
  }
  next()
})

export default router